# Maintainer: J. Peter Mugaas

_realname=pep517
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.7.0
pkgrel=1
pkgdesc="Wrappers to build Python packages using PEP 517 hooks (mingw-w64)"
arch=('any')
url="https://github.com/takluyver/pep517"
license=('MIT')
validpgpkeys=('gpg_KEY')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2-pytoml" 
             "${MINGW_PACKAGE_PREFIX}-python3-pytoml"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest"
              "${MINGW_PACKAGE_PREFIX}-python3-testpath")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.io/packages/source/p/pep517/pep517-$pkgver.tar.gz")
sha512sums=('6c59dd41ec05e5f3b5032ed2d262f4fc4ba51d31cd7e8115f8f128a3e56b9e8ba1ec6140f37be6370561618ab8ad9845422b144db09e6102f8178a2c52756b2a')

prepare() {
  cd "${srcdir}"
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "${_realname}-${pkgver}" "${builddir}"
  done
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {
# THere is NO python2-testpath
    msg "Python 3 test for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/pytest
}

package_python3-pep517() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-pep517() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-pep517() {
  package_python2-pep517
}

package_mingw-w64-i686-python3-pep517() {
  package_python3-pep517
}

package_mingw-w64-x86_64-python2-pep517() {
  package_python2-pep517
}

package_mingw-w64-x86_64-python3-pep517() {
  package_python3-pep517
}
